package fr.sedoo.commons.client.news.widget;

import com.google.gwt.cell.client.Cell.Context;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;

import fr.sedoo.commons.client.message.CommonMessages;
import fr.sedoo.commons.client.news.bundle.NewsMessages;
import fr.sedoo.commons.client.util.DateUtil;
import fr.sedoo.commons.client.util.StringUtil;
import fr.sedoo.commons.shared.domain.message.TitledMessage;

public class TitledMessageRenderer {

	public static void render(Context context, TitledMessage value, SafeHtmlBuilder sb, String language) {
		if (value == null) {
			return;
		}

		sb.appendHtmlConstant("<table width=\"100%\" style=\"border-bottom: 1px solid #EEEEEE;text-align:justify;cursor:default\" class=\"localCellList\">");
		sb.appendHtmlConstant("<tr><td><div style=\"border-bottom: 3px; border-bottom-style:solid; border-bottom-color:transparent;\">");
		sb.appendHtmlConstant("<span class=\"green-small-button\"> MESSAGE </span>&nbsp;<b>" + StringUtil.trimToEmpty(value.getTitle()) + "</b>");
		sb.appendHtmlConstant("<i> (" + NewsMessages.INSTANCE.addedOrModified() + " " + DateUtil.getDateByLocale(value.getDate(), language) + " " + CommonMessages.INSTANCE.by() + " "
				+ StringUtil.trimToEmpty(value.getAuthor()) + ")</i></div>");
		sb.appendHtmlConstant(StringUtil.trimToEmpty(value.getContent()));
		sb.appendHtmlConstant("</td></tr>");
		sb.appendHtmlConstant("</table>");
	}

}
